package cn.shangqizhenshuai.sqiot.Serivce.impl;

import cn.shangqizhenshuai.sqiot.Serivce.AreaService;
import cn.shangqizhenshuai.sqiot.entity.Area;
import cn.shangqizhenshuai.sqiot.entity.AreaExample;
import cn.shangqizhenshuai.sqiot.mapper.AreaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("areaService")
public class AreaServiceImpl implements AreaService {

    @Autowired
    private AreaMapper areaMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Area> getlist() {
        AreaExample areaExample = new AreaExample();
        areaExample.createCriteria().andIdIsNotNull();
        List<Area> areas = areaMapper.selectByExample(areaExample);
        return areas;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int add(String name) {
        Area area = new Area();
        area.setName(name);
        return  areaMapper.insert(area);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int del(int id) {
        AreaExample areaExample = new AreaExample();
        areaExample.createCriteria().andIdEqualTo(id);
        Integer i = areaMapper.deleteByExample(areaExample);
        return i;
    }
}
